import { login } from "~/apis/user";
import { to, toast, set, err } from "~/utils/wxapi";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    mobile: "",
    password: "",
  },
  async subLogin() {
    try {
      const { mobile, password } = this.data;
      const res: any = await login({ mobile, password });
      console.log(res);
      if (res.code === 200) {
        const user = res.data.item
        set('user', user)
        toast('登录成功')
        setTimeout(() => {
          wx.switchTab({ url: '/pages/my/my' })
        }, 1500)
      }
    } catch (error) {
      err(error);
    }
  },
  toRegister() {
    to("/pages/register/register");
  },
});
